<template>
	<watermark>
		<view class="tab">
			<z-paging ref="paging" v-model="listAll" loading-more-no-more-text="暂无更多数据" @query="queryList">
				<view class="tab-title" slot="top">
					<view v-for="(title , index) in titleList" :key="index">
						<view :class="index==tabIndex?'border-bottom1':'border-bottom2'" @click="switchTab(index)">
							{{title.stateDesc}}
						</view>
					</view>
				</view>

				<view slot="top">
					<button type="primary" style="width: 80%;line-height: 60rpx;" v-if="tabIndex!=2"
						@click="addHotWork">提交隐患</button>
					<view v-else style="text-align: center;align-items: center;">
						{{equipment.departmentName}}收到的隐患
					</view>
					<input class="input-border input-margin" type="text" placeholder="请输入隐患描述查询" />
					<view
						style="border: #666 0.4px solid;border-radius: 1rem;display: flex;margin: 0.5rem 1rem;color: #666;padding: 0px 1rem;">
						<view class="view-flxe v-user-delete">
							<view class="iconfont icon-jiantouht view-flxe" style="color: black;">状态</view>
							<view class="uni-list-cell-db">
								<picker @change="clickSelectStatus" :value="index" :range="statusArray">
									<view class="uni-input">{{statusArray[index]}}</view>
								</picker>
							</view>
							<!-- <view>{{'全部'}}</view> -->
						</view>
						<view style="width: 1px;border-left: #666 1px solid;"></view>
						<view class="view-flxe v-user-delete">
							<view class="iconfont icon-jiantouht view-flxe" style="color: black;">年份</view>
							<view class="uni-list-cell-db">
								<picker @change="clickSelectYear" :value="yearIndex" :range="yearArray">
									<view class="uni-input">{{yearArray[yearIndex]}}</view>
								</picker>
							</view>
						</view>
						<view style="width: 1px;border-left: #666 1px solid;"></view>
						<view class="view-flxe v-user-delete" @click="clickSelectMonth">
							<view class="iconfont icon-jiantouht view-flxe" style="color: black;">月份</view>
							<view class="uni-list-cell-db">
								<picker @change="clickSelectMonth" :value="monthIndex" :range="monthArray">
									<view class="uni-input">{{monthArray[monthIndex]}}</view>
								</picker>
							</view>
						</view>
					</view>
					<view style="width: 100%;align-items: center;text-align: center;">总计{{listAll.length}}数据</view>
				</view>

				<view v-for="(item,index) in listAll" :key="index" style="border: 1px solid #eee;padding: 1rem;"
					@click="clickItem">
					<view class="item-line">
						<view>电焊</view>
						<view>2024-06-27</view>
					</view>
					<view class="item-line" style="color: #666;">
						<view>总装护栏-1</view>
						<view>待签名</view>
					</view>

				</view>
			</z-paging>
		</view>
	</watermark>
</template>

<script>
	import hotWorkApi from "@/pages_psm/api/permit-to-work/hot_work.js"
	import hiddenDangerReviewApi from "@/pages_psm/api/hidden-danger/hidden-danger-review.js"
	export default {
		data() {
			let date = new Date()
			return {
				index: 0,
				yearIndex: 1,
				monthIndex: date.getMonth(),
				listAll: [{
					aaa: 1
				}],
				statusArray: [
					"全部",
					"待审批"
				],
				yearArray: [date.getFullYear() - 1 + "", "" + date.getFullYear(), date.getFullYear() + 1 + ""],
				monthArray: ["1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月"],
				titleList: [{
						stateValue: "0",
						stateDesc: "我提交的"
					},
					{
						stateValue: "1",
						stateDesc: "我收到的"
					}, {
						stateValue: "2",
						stateDesc: "部门隐患"
					}
				],

				tabIndex: 0,
				equipment: {
					departmentName: '' //部门名称
				}
			}
		},
		methods: {
			/**
			 * 选择月份
			 */
			clickSelectMonth(e) {
				this.monthIndex = e.detail.value
			},
			/**
			 * 选择年
			 */
			clickSelectYear(e) {
				this.yearIndex = e.detail.value
			},
			/**
			 * 选择状态
			 */
			clickSelectStatus(e) {
				this.index = e.detail.value
			},
			switchTab(index) {
				this.tabIndex = index
			},
			queryList(pageNo, pageSize) {
				var that = this
				const params = {
					page: pageNo,
					limit: pageSize * 3
				}
				///测试数据
				setTimeout(() => {
					that.$refs.paging.complete([{
						aaa: 1
					}]);
				}, 200);

			},
			/**
			 * 点击条目

			 * @param {Object} item
			 */
			clickItem(item) {
				uni.navigateTo({
					url: "/pages_psm/model/hidden-danger/hidden-danger-review/hidden-danger-review-info"
				})
			},
			/**
			 * 新增动火申请
			 */
			addHotWork() {
				uni.navigateTo({
					url: "/pages_psm/model/hidden-danger/hidden-danger-review/hidden-danger-review-add"
				})
			},
			getUserOrganizationInfoByCondition() {
				var that = this;
				var userCode = uni.getStorageSync("userInfo")?.userCode;
				hiddenDangerReviewApi.getUserOrganizationInfoByCondition({
					"userCode": userCode
				}, (result) => {
					if (result.data) {
						that.equipment.departmentName = result.data.workProcedureName ? result.data
							.workProcedureName : '';
					}
				}, (error) => {
					uni.showModal({
						title: '用户所在班组查询失败',
						content: error.msg,
						showCancel: false
					});
				});
			}
		},
		onLoad(){
			this.getUserOrganizationInfoByCondition()
		}
	}
</script>


<style>
	@import url("/pages_psm/model/permit-to-work/common-style.css");
</style>